package com.zhangmeng.service.impl;

import cn.hutool.log.Log;
import cn.hutool.log.LogFactory;
import com.zhangmeng.service.Request;
import com.zhangmeng.utils.ByteBufferUtil;

import java.io.IOException;
import java.io.OutputStream;
import java.nio.charset.StandardCharsets;

/**
 * @author zm
 * @date 2025/2/27 11:35
 * @version: 1.0
 */
public class HelloRouter extends BaseRouterImpl {
    private final Log log = LogFactory.get();

    @Override
    public void Handle(Request request) {
        log.info("Call HelloRouter Handle");
        //先读取客户端的数据，再回写ping...ping...ping
        log.info("recv from client : msgId={}, data={}", request.GetMsgID(), new String(request.GetData(), StandardCharsets.UTF_8));
        try {
            OutputStream outputStream = request.GetConnection().GetTCPConnection().getOutputStream();
            ByteBufferUtil.sendMsg(1, "Hello Router V0.6".getBytes(), outputStream);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
